import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '@/views/login/loginView.vue'
import LayoutView from '@/views/layout/layoutView.vue'
import HomeView from '@/views/home/homeView.vue'
import CategoryView from '@/views/category/categoryView.vue'
import SubCategoryView from '@/views/subCategory/subCategoryView.vue'
import DetailView from '@/views/detail/detailView.vue'
import CartList from '@/views/cartList/cartListView.vue'
import Checkout from '@/views/checkout/checkoutView.vue'
import Pay from '@/views/pay/payView.vue'
import PayBack from '@/views/payBack/payBack.vue'
import MemberView from '@/views/member/memberView.vue'
import UserInfo from '@/views/member/userInfo.vue'
import UserOrder from '@/views/member/userOrder.vue'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: 'login',
      component: LoginView
    },
    {
      path: '/',
      component: LayoutView,
      //children:
      children:
        [
          {
            path: '',
            name: 'home',
            component:HomeView
          },
          {
            path: 'category/:id',
            name: 'category',
            component: CategoryView
          },
          {
            path: 'category/sub/:id',
            name: 'subCategory',
            component: SubCategoryView
          },
          {
            path: 'detail/:id',
            name: 'detail',
            component: DetailView
          },
          {
            path: 'cartlist',
            name: 'cartlist',
            component: CartList
          },
          {
            path: 'checkout',
            name: 'checkout',
            component: Checkout
          },
          {
            path: 'pay',
            name: 'pay',
            component: Pay
          },
          {
            path: 'paycallback',
            name: 'paycallback',
            component: PayBack
          },
          {
            path: 'member',
            name: 'member',
            component: MemberView,
            children: [
              {
                path: '',
                name: 'userinfo',
                component: UserInfo
              },
              {
                path: 'order',
                name: 'userorder',
                component: UserOrder
              }
            ]
          }
        ]
    },
  ],
  //路由滚动行为  切换后 返回滚动位置（到顶部）
  scrollBehavior () {
    return { top: 0 }
  }
})

export default router
